package com.bai.Service.Impl;

import com.bai.Constant.ResultConst;
import com.bai.Mapper.PrisonerMapper;
import com.bai.Pojo.Admin;
import com.bai.Pojo.Prisoner;
import com.bai.Service.PrisonerService;
import com.bai.Utils.DtoResultUtil;
import com.bai.dto.PageLimitDto;
import com.bai.dto.PublicResponseBody;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @title: PrisonerServiceImpl
 * @Author BaiSc
 * @Date: 2021/6/13 11:21
 * @Version 1.0
 *
 */
@Transactional
public class PrisonerServiceImpl implements PrisonerService {

    public void setPrisonerMapper(PrisonerMapper prisonerMapper) {
        this.prisonerMapper = prisonerMapper;
    }

    @Autowired
    private PrisonerMapper prisonerMapper;
    //添加
    @Override
    public PublicResponseBody addPrisoner(Prisoner prisoner) {
        int addPrisoner = prisonerMapper.addPrisoner(prisoner);
        if (addPrisoner>0){
            return DtoResultUtil.resultSuccess();
        }else {
            return DtoResultUtil.result(-1,ResultConst.add_error);
        }
    }

    //修改
    @Override
    public PublicResponseBody UpdatePrisoner(Prisoner prisoner) {
        int updatePrisoner = prisonerMapper.UpdatePrisoner(prisoner);
        if (updatePrisoner>0){
            return DtoResultUtil.resultSuccess();
        }else {
            return DtoResultUtil.result(-1,ResultConst.edit_error);
        }
    }

    //删除根据ID
    @Override
    public PublicResponseBody deletePrisonerById(Integer id) {
        int deletePrisonerById = prisonerMapper.deletePrisonerById(id);
        if (deletePrisonerById>0){
            return DtoResultUtil.resultSuccess();
        }else {
            return DtoResultUtil.result(-1, ResultConst.delete_error);
        }
    }

    @Override
    public PageLimitDto QueryAll(String prisex,String partition, String charge,Integer offset, Integer limit) {
        PageLimitDto pageLimitDto=new PageLimitDto();
        pageLimitDto.setTotal(prisonerMapper.queryAllPriCount(prisex,partition,charge));
        pageLimitDto.setRows(prisonerMapper.QueryAll(prisex,partition,charge,offset,limit));
        return pageLimitDto;
    }

    @Override
    public int deletePrisonerByName(String priname) {
       return  prisonerMapper.deletePrisonerByName(priname);
    }

    @Override
    public PublicResponseBody queryPrisonerById(Integer id) {

        Prisoner prisoner = prisonerMapper.queryPrisonerById(id);
        if (prisoner!=null){
            return DtoResultUtil.resultSuccess(prisoner);
        }else {
            return DtoResultUtil.result(-1,ResultConst.add_error);
        }
    }

    @Override
    public PublicResponseBody queryPrisonerDetailsById(Integer id) {
        Prisoner prisoner = prisonerMapper.queryPrisonerDetailsById(id);
        if (prisoner!=null){
            return DtoResultUtil.resultSuccess(prisoner);
        }else {
            return DtoResultUtil.result(-1,ResultConst.query_error);
        }
    }

    @Override
    public Prisoner queryPrisonerByName(String priname) {
        return prisonerMapper.queryPrisonerByName(priname);
    }


}
